#ifndef OCSPLIT_H_INCLUDED
#define OCSPLIT_H_INCLUDED

#include <glib.h>
#include "ockvpair.h"


typedef struct
{
    GArray                  *kvpair_array;
    gulong                 granularity;
}oc_split_t;

static inline
oc_key_val_pair_t *oc_split_get_kvpair ( oc_split_t  *split,
                                            gulong             i )
{
    return & g_array_index ( split->kvpair_array, oc_key_val_pair_t, i );
}

static inline
gulong oc_split_get_granularity ( oc_split_t  *split
                                            )
{
    return split->granularity;
}

static inline
oc_split_t  *oc_split_new ( oc_task_range_t *task_range,
                            gulong     i,
                            gulong     granularity )
{
    oc_split_t *split = g_slice_alloc ( sizeof ( oc_split_t ) );
    split->kvpair_array = g_array_sized_new (   FALSE,
                                                FALSE,
                                                sizeof ( oc_key_val_pair_t ),
                                                granularity );
    split->granularity = granularity;
    oc_task_range_set_task ( task_range, i, ( gpointer ) split );
    return split;
}

static inline
void oc_split_add_kvpair (  //oc_task_range_t     *task_range,
                            //gulong             i,
                            oc_split_t          *split,
                            void                *key,
                            void                *value      )
{
    //oc_split_t *split = ( oc_split_t * ) oc_task_range_get_task ( task_range, i );

    oc_key_val_pair_t kvpair;
    oc_key_val_pair_set ( & kvpair, key, value );
    g_array_append_val ( split->kvpair_array,
                                kvpair        );

}

void oc_split_destroy ( //oc_task_range_t *task_range,
                        //gulong     i
                        oc_split_t          *split
                        )
{
    //oc_split_t *split = ( oc_split_t * ) oc_task_range_get_task ( task_range, i );
    g_array_free ( split->kvpair_array, TRUE );
    g_slice_free1 ( sizeof ( oc_split_t ), split );
}

#endif // OCSPLIT_H_INCLUDED
